<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<input type="text" name="coupon_name" id="coupon_name" placeholder="优惠券名称" class="layui-input">
		</div>
		<div class="layui-inline">
			<input type="text" name="activity_name" id="activity_name" placeholder="活动名称" class="layui-input">
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
			<?php if(!empty($admin_activity_id)):?>
			<button class="layui-btn layui-btn-normal" data-url="{:url('addCoupon','admin_activity_id=')}<?php echo $admin_activity_id?>" onclick="add_t(this,'添加优惠券')">
				添加优惠券
			</button>
			<?php endif;?>
			<?php if(empty($admin_activity_id)):?>
			<button class="layui-btn" onclick="javascript:history.back(-1);">返回上一页</button>
			<?php endif;?>
		</div>
	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('AdminActivity/couponList')}', page: true, limit: 10,where: { admin_activity_id: <?php echo $admin_activity_id;?>}, id:'couponList'}" lay-filter="couponList">
		<thead>
		<tr>
			<th lay-data="{field:'coupon_id', width:80,fixed: true, sort: true,align:'center'}">ID</th>
			<th lay-data="{field:'activity_name', width:180,align:'center'}">活动名称</th>
			<th lay-data="{field:'coupon_name', width:180,align:'center'}">优惠券名称</th>
			<th lay-data="{field:'isRecommedName', width:120,align:'center'}">领取方式</th>
			<th lay-data="{field:'moneyTypeName', width:100,align:'center'}">优惠券类型</th>
			<th lay-data="{field:'over_money', width:100,align:'center'}">满(元)</th>
			<th lay-data="{field:'money', width:100,align:'center'}">优惠/折扣</th>
			<th lay-data="{field:'couponNum', width:120,align:'center'}">数量(优惠券)</th>
			<th lay-data="{field:'use_num', width:100,align:'center'}">已使用</th>
			<th lay-data="{field:'receiveTypeName', width:120,align:'center'}">发放方式</th>
			<th lay-data="{field:'admin_name', width:100,align:'center'}">添加者</th>
			<th lay-data="{field:'time', width:160,align:'center'}">添加时间</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:240, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 40px">修 改</a>
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="use_coupon" style="width: 40px;">查 看</a>
		{{#  if(d.couponNum == 0){ }}
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 40px">删 除</a>
		{{#  } }}
		<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="supply" style="width: 40px">补 发</a>
	</script>
	<script>
		layui.use(['form','table'], function () {
			var table = layui.table,form = layui.form;
			table.on('tool(couponList)', function (obj) {
				var data = obj.data;
				var coupon_id = data.coupon_id;
				if (obj.event === 'del'){
					layer.confirm('确定删除吗?',function(index){
						var url = '{:url("/admin/Coupon/del","coupon_id=")}' + coupon_id
						$.get(url,function(data){
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
								window.location.reload();
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						},'json')
						layer.close(index);
					})
				} else if (obj.event === 'use_coupon') {
					layer.open({
						type: 2,
						title: '优惠券发放信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/admin_activity/couponDetail","coupon_id=")}' + coupon_id //iframe的url
					});
				}else if (obj.event === 'edit') {
					layer.open({
						type: 2,
						title: '编辑优惠券',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/admin_activity/editCoupon","coupon_id=")}' + coupon_id //iframe的url
					});
				}else if (obj.event === 'supply') {
					$.ajax({
						url:'{:url("/admin/AdminActivity/supplyCoupon")}',
						async:true,
						dataType:'json',
						type:'post',
						data: {'coupon_id':coupon_id},
						success:function(res){
							if(res.code==1){
								layer.open({
									type: 2,
									title: '补发优惠券',
									shadeClose: true,
									shade: 0.8,
									area: ['90%', '90%'],
									content: '{:url("/admin/admin_activity/supplyCoupon","coupon_id=")}' + coupon_id //iframe的url
								});
							}else{
								layer.msg(res.msg,{icon: 5});
							}
						}
					});
				}
			});
			//搜索
			$('.layui-btn').on('click', function () {
				var activity_name 	= $("#activity_name").val();
				var coupon_name		= $("#coupon_name").val();
				table.reload('couponList', {
					url: '/admin/AdminActivity/couponList', where: {
						"activity_name": activity_name,
						"coupon_name": coupon_name,
						"admin_activity_id":'<?php echo $admin_activity_id;?>'
					}
				});
			});
		});
	</script>
</block>
